<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>注册</title>
		<meta name="keywords" content="" />
		<meta name="description" content="" />
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<meta name="format-detection" content="telephone=no" />
		<meta name="format-detection" content="email=no" />
		<meta name="apple-mobile-web-app-capable" content="yes" />
		<meta name="apple-mobile-web-app-status-bar-style" content="black" />
		<meta name="msapplication-tap-highlight" content="no">
		<link rel="stylesheet" href="css/common.css" />
		<link rel="stylesheet" href="css/register.css" />
		<link rel="stylesheet" href="layer_mobile/need/layer.css" />
		<script type="text/javascript" src="js/font-size.js"></script>
		<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
		<script type="text/javascript" src="layer_mobile/layer.js"></script>
		<script type="text/javascript" src="js/register.js"></script>
		<script type="text/javascript" src="js/global_variable.js" ></script>
	</head>
	<body style="background:#fff;">
		<div class="container">
			<header>
				<div class="title_top">
					<a href="login.html" class="title_top_first">
						<img src="img/back.png" class="hea_img" />
					</a>
					<span class="title_top_center">注册</span>
				</div>

			</header>
			<div class="main">
				<div class="main_bak_login">
					<div class="photo_img">
					<img src='img/login/dribs.png' class="photo_img_bg">
						<p class="photo_img_p">
							<img src="img/login/palm.png" />
						</p>
					</div>
					<div class="main_infor">
						<p class="main_info_hint">短信验证码即将发送至<span></span></p>
						<ul class="main_infor_name">
							<li class="name_li name_input">
								<input type="text" placeholder="请输入验证码" class="yzm" id="phone_codema" />
								<input type="button" value="获取验证码" id="btn_phonecode" class="btn_yanzhengma" />
							</li>
							<li class="name_li name_input">
								<input type="password" placeholder="请设置6-18位密码" id="pwd" onkeyup="this.value = this.value.substring(0,18)" />
								<span class="huoqu_yanzhengma pwd_showhide">
								<img src="img/password_hide.png"  class="icon-yanjing"/>
							</span>
								<span class="huoqu_yanzhengma pwd_showhide">
								<img src="img/password_show.png"  class="icon-yanjing-copy"/>	
							</span>
							</li>
							<li class="name_li name_input">
								<input type="number" placeholder="请输入邀请码(选填)" id="invite_code" />
							</li>
						</ul>
						
					</div>
					<p class="fuwutiaokuan">
						继续注册表示已阅读并同意
						<a href="Agreement.html" style="color:#b61c25;">《服务条款》</a>
					</p>
					<!--输入手机号验证码结束-->
					<div class="main_btn">
						<button type="button" class="main_btn_a mian_btn_login" disabled="">
							完成
						</button>
					</div>
				</div>
				<!--登录结束-->
				<p class="loginin_num">
					<a href="login.html">
						已有账号？请登录
					</a>
				</p>

			</div>
		</div>
		<script>
			$(function() {
				var namePhone = localStorage.getItem('name');
				$('.main_info_hint span').html(namePhone);
				/*密码 可见不可见 */
				$(".pwd_showhide").click(function() {
					var _type = $(this).siblings("input").attr("type");
					if(_type == "password") {
						$(this).siblings("input").attr("type", "text");
						$(".icon-yanjing-copy").show();
						$(".icon-yanjing").hide();
					} else if(_type == "text") {
						$(this).siblings("input").attr("type", "password");
						$(".icon-yanjing-copy").hide();
						$(".icon-yanjing").show();
					}
				});

				//	验证码
				var x = 60;
				$(".btn_yanzhengma").click(function() {
					$('.main_info_hint').css('display','block');
					if(x == 60) {
						var cl = setInterval(function() {
							if(x != 0) {
								x = x - 1;
								$(".btn_yanzhengma").val(x + "s");

							} else {
								$(".btn_yanzhengma").val("获取验证码");
								x = 60;
								clearInterval(cl);
							}
						}, 1000);
					}

					var data = {
						method: 'getVerificationCodeOptimize',
						phone: namePhone,
						url_type:'user'
					}
					/*调用获取验证码接口*/
					$.ajax({
						url: domain_name_url + "/user",
						type: "GET",
						dataType: "jsonp", //指定服务器返回的数据类型
						data: data,
						success: function(data) {
							var result = JSON.stringify(data); //json对象转成字符串
							if(data.success==1){

							}
							if(data.success==2){
								layer.open({
									content:data.errorMessage,
									skin: 'msg',
									time: 2
								});
							}
						}
					});
					
				});
				$('#phone_codema').blur(function(){
					var phone_codema = document.getElementById('phone_codema').value;
					if(phone_codema==''){
						layer.open({
							content: '请输入验证码',
							skin: 'msg',
							time: 2
						});
					}else{
						$('.mian_btn_login').removeAttr('disabled');
						$('.mian_btn_login').css({'background':'#b61c25','color':'#fff'});
					}
				})
				//密码格式验证
				$("#pwd").blur(function() {
					var pwdreg = /^[0-9a-zA-Z]{6,18}$/;
					var pwd = $('#pwd').val().replace(/\s+/g, "");
					var newpwd = document.getElementById("pwd").value;
					if(newpwd==''){
						layer.open({
							content: '请输入密码',
							skin: 'msg',
							time: 2
						});
					}else if(!pwdreg.test(pwd)) {
						layer.open({
							content: '密码格式不正确',
							skin: 'msg',
							time: 1
						});

					} else {
						$('.mian_btn_login').removeAttr('disabled');
						$('.mian_btn_login').css({'background':'#b61c25','color':'#fff'});
					}
				});
				//邀请码
				$('#invite_code').blur(function(){
					var reg = /^1[3|4|5|7|9|6|8][0-9]\d{4,8}$/;
					var invite_code = $('#invite_code').val().replace(/\s+/g, "");
					if(!reg.test(invite_code)) {
						layer.open({
							content: '手机号格式不正确',
							skin: 'msg',
							time: 2
						});
						return false;
					}
				})
				//点击完成
				$(document).on("click", ".mian_btn_login", function() {
					var phone_codema = document.getElementById('phone_codema').value;
					var newpwd = document.getElementById("pwd").value;
					var invite_code = document.getElementById('invite_code').value;
					if(phone_codema==''){
						layer.open({
							content: '请输入验证码',
							skin: 'msg',
							time: 2
						});
						return false;
					}
					if(newpwd==''){
						layer.open({
							content: '请输入密码',
							skin: 'msg',
							time: 2
						});
						return false;
					}
					var data = {
						method: 'addUserOptimize',
						phone: namePhone,
						pwd: newpwd,
						code: phone_codema,
						inviteCode:invite_code,
						source: '1',
						url_type:'user'
					}
					$.ajax({
						url: domain_name_url + "/user",
						type: "GET",
						dataType: "jsonp", //指定服务器返回的数据类型
						data: data,
						success: function(data) {
							var result = JSON.stringify(data); //json对象转成字符串
							var da_success = data.success;
							if(da_success == 1) {
								layer.open({
									content: '注册成功',
									skin: 'msg',
									time: 2 //2秒后自动关闭
								});
								setTimeout("location.href='login.html'", 1000);
							} else if(da_success == 2){//短信验证码错误
								layer.open({
									content: data.errorMessage,
									skin: 'msg',
									time: 2 //2秒后自动关闭
								});
								$('.mian_btn_login').attr('disabled',true);
								$('.mian_btn_login').css({'background':'#ebebeb','color':'#b3b3b3'});
							}else if(data.success==3){//邀请人不存在
								layer.open({
									content: data.errorMessage,
									skin: 'msg',
									time: 2 //2秒后自动关闭
								});
								$('.mian_btn_login').attr('disabled',true);
								$('.mian_btn_login').css({'background':'#ebebeb','color':'#b3b3b3'});
							}
						}
					});

				});

			})
		</script>

	</body>

</html>